package org.lanqiao.api.cart;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.common.Constants;
import org.lanqiao.common.JsonResult;
import org.lanqiao.common.JsonResultWriter;
import org.lanqiao.service.CartServiceImpl;


/**
 * 查询所有购物车接口的实现
 * @author dzp
 *
 */

@WebServlet("/api/cart/select")
public class SelectCartServlet extends HttpServlet {
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		JsonResult result=null;
				
		CartServiceImpl addCartService = new CartServiceImpl();
		//查询传入用户ID
		String userId = request.getParameter("UserId");
		
		List list = addCartService.selectAllCart(userId);
		
		try {
	
			if(list.size()>0){	
				result = new JsonResult("查询成功",Constants.STATUS_SUCCESS,list);
			}else if(list.size()==0) {
				result = new JsonResult("购物车为空，请到购物车页面去",Constants.STATUS_UNLOGIN);				
			}
			else {				
				result = new JsonResult( "查询失败",Constants.STATUS_UNFOUND);
			}}catch (Exception e) {			
			result = new JsonResult("查询异常",Constants.STATUS_FAILURE,  e.getMessage());
		}


		JsonResultWriter.writer(response, result);


	}
}